<?php
Yii::app()->clientScript->registerScript('info', "
    var eid='$model->id';
      var custno='$model->custno';
        var locno='$model->locno';
    ", CClientScript::POS_HEAD); ?>
<?php Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/app/equipmentUpdate.js', CClientScript::POS_BEGIN); ?>


<div id="left-col">
    <?php $this->renderPartial('_side',array(
        'location'=>$location,
        'customer'=>$customer,
         'action'=>'update'
    ))?>
    

</div>

<div id="right-col">

    <div class="wrap">
        <div class="container">

            
            <div id="breadcrumb" style="display:none;"><span style="padding-left:10px;font-size:10px;color:#777777;" id="alsoviewing"></span></div>
            <div class="inside">

                <h1>Update Equipment</h1>

                <br/>
                <ul id="tab" class="tabs tabs-with-summary">
                    <li class="active"><a href="#tabUpdate">Info</a></li>
                    <li><a href="#tabSchedule">Schedule</a></li>
                    <li ><a href="#tabContracts" > Contracts</a></li>
                    <li><a href="#notes" class='unavailable'>Notes</a></li>
                    <li><a href="#dispatch" class='unavailable'>Dispatch</a></li>


                    </ul>
                <div id="tab1"></div>
                <div id = "tabUpdate">
                    <br>
                <?php $this->renderPartial('_form',array(
                    'model'=>$model,
                ));?>
                </div>
                <div id = "tabSchedule">
                    <br>
                    <?php $this->renderPartial('_sform',array(
                    'model'=>$schedule_model
                ));?>
                </div>
                <div id="tabContracts">
                    <br clear=both/>
                    <?php
                        $sql = "SELECT *
                        FROM tbl_contracts AS c, tbl_contract_equipment AS ce
                        WHERE c.contractid = ce.contractid
                        AND ce.equipmentid = $model->id";
                    $contractsList =    Yii::app()->db->createCommand($sql)->queryAll();
                        $criteria = new CDbCriteria();
                        $criteria->condition ='inactive=0';
                        $criteria->order = 'sort Asc';
                        $data = ContractStatus::model()->findAll($criteria);

                    ?>
                       <br/>
                    <?php
                    foreach ($data as $type):
                    ?>
                     
                        <?php 
                        echo CHtml::link("<b>$type->description</b>",'#',array('onclick'=>"showData($type->id)"));
                        $table = new CI_Table();
                        $table->set_template(array(
                            'table_open'=>'<table width="600px" border="1">'
                        ));
                        $table->set_heading(
                            'Type',
                            'Contract No',
                            'Start date',
                            'End date',
                            'Coverage',
                            'Line service',
                            'PM'
                        );
                        ?>
                        <div id="list-id-<?=$type->id?>" <?php if($type->sort!=0):?> style="display: none"<?php endif;?>   >
                        <?php foreach($contractsList as $contract) :?>
                            

                                <?php if($contract['status']==$type->id):?>
                                <?php $temp_model = new ContractEquipment();
                                $sl = FlOptions::model()->findByPk($contract['sl']) ;
                                $temp_model->attributes = $contract;
                                $pm = $contract['pmr'] == 1 ?'Yes':'No';
                                $table->add_row(
                                    ContractType::getText($contract['contractype']),
                                    CHtml::link($contract['contractid'],array('contracts/update','contractid'=>$contract['contractid']),array(
                                        'target'=>'_blank'
                                    )),
                                    $contract['contractstartdate'],
                                    $contract['contractenddate'],
                                    $temp_model->getPlanTypeText(),
                                    $sl->description,
                                    $pm
                                );
                                ?>
                          

                                    <?php endif;?>
                            
                            <?php endforeach;?>
                            <?php echo $table->generate(); ?>
                        </div>
                            <br/>
                    <?php endforeach; ?>
                </div>
                


                
            </div><!-- inside -->
        </div><!-- container -->
    </div><!-- wrap -->
    <?php $this->renderPartial('/copyright'); ?>
</div> <!-- left-col -->
<script type="text/javascript">
    function showData(id){
        $("#list-id-"+id).fadeToggle();
    }
</script>
